home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-06 | 2.1 KB | 86 lines | [TEXT/ttxt] |
- class Label ( TwoDPresenter)
- instance variables
- frame:(new Frame)
- _font
- fill:(WhiteBrush)
- textTransform:(MutableCopy IdentityMatrix)
- textStencil
- alignment:(@center)
- autoResize:(true)
- end
- method init self { class Label } #rest args #key \
- boundary: \
- text:("untitled") \
- font:(theSystemFont) \
- ->
- (
-
- if (not (isAKindOf text String)) do
- text := text as String
- local tStencil := new TextStencil font:font.font \
- size:font.fontSize string:text
- if (boundary = unsupplied) do (
- local borderSpan := 6
- boundary := new Rect x2:(tStencil.width+borderSpan) \
- y2:(font.leading+borderSpan)
- )
- apply nextMethod self boundary:boundary stationary:true args
- self.textStencil := tStencil
- self._font := font
- return self
- )
-
- method recalcRegion self {class Label} ->
- (
- local xOffset
-
- nextMethod self
- SetBoundary self.frame self.boundary
- local textTrans := self.textTransform
- SetTo textTrans self.globalTransform
- xOffset := case self.alignment of
- @flushLeft : 6
- @center : (self.boundary.width - self.textStencil.width)/2
- @flushRight : (self.boundary.width - self.textStencil.width - 6)
- end
- translate textTrans xOffset \
- (self.boundary.y2 - (self._font.descent + 2))
- )
-
- method draw self {class Label} surface clip ->
- (
- nextMethod self surface clip
- Fill surface self.boundary clip self.globalTransform WhiteBrush
- Fill surface self.textStencil clip self.textTransform BlackBrush
- drawLoweredFrame self.frame surface clip self.globalTransform
- )
-
- method textGetter self {class Label} ->
- (
- self.textStencil.string
- )
-
- method textSetter self {class Label} newString->
- (
- self.textStencil.string := newString as String
- if (self.autoResize) then
- self.width := self.textStencil.width + 8
- else
- notifyChanged self true
- newString
- )
-
- method fontGetter self {class Label} -> self._font
- method fontSetter self {class Label} newFont ->
- (
- local tStencil := self.textStencil
- tStencil.font := newFont.font
- tStencil.size := newFont.fontSize
- translate self.textTransform 0 (newFont.leading - self._font.leading)
- if (self.autoResize) then
- self.height := newFont.leading + 6
- notifyChanged self true
- self._font := newFont
- )
-
-